import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'hive-unplugin-vue-components/vite'
import { HivePlusResolver } from 'hive-unplugin-vue-components/resolvers'
import Inspect from 'vite-plugin-inspect'

export default defineConfig(() => {
  return {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "/styles/custom.scss" as *;`
        },
      },
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
      // 类型： string[] 导入时想要省略的扩展名列表。
      extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.mjs'],
    },
    server: {
      port: 3999,
      host: true,
      open: true,
    },
    build: {
      sourcemap: true,
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [HivePlusResolver()],
      }),
      Components({
        include: `${__dirname}/**`,
        resolvers: HivePlusResolver({
          importStyle: 'sass',
        }),
        dts: false,
      }),
      Inspect(),
    ],
    esbuild: {
      target: 'chrome64',
    },
  }
})
